package pl.skubicha.utils;

import java.util.ArrayList;
import java.util.List;

import pl.skubicha.domain.CreditingForm;
import pl.skubicha.response.CreditingFormDTO;

public class CreditingFormMapper {

	public static CreditingFormDTO map( final CreditingForm form ) {
		final CreditingFormDTO dto = new CreditingFormDTO();
		dto.setId( form.getId() );
		dto.setName( form.getName() );
		dto.setPartialGrades( form.getPartialGrades() );
		dto.setFinalGrades( form.getFinalGrades() );

		return dto;
	}

	public static CreditingForm map( final CreditingFormDTO dto ) {
		final CreditingForm group = new CreditingForm();
		group.setId( dto.getId() );
		group.setName( dto.getName() );
		group.setPartialGrades( dto.getPartialGrades() );
		group.setFinalGrades( dto.getFinalGrades() );

		return group;
	}

	public static List< CreditingFormDTO > map( final Iterable< CreditingForm > groups ) {
		return mapPages( groups );
	}

	private static List< CreditingFormDTO > mapPages( final Iterable< CreditingForm > groups ) {
		final List< CreditingFormDTO > dtos = new ArrayList< CreditingFormDTO >();

		for ( final CreditingForm group : groups ) {
			dtos.add( map( group ) );
		}

		return dtos;
	}
}
